﻿// 
// SoapTrace.Net - A soap message monitoring utility. 
// 
// Copyright (C) 2004 Matthew Ward
// 
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
// 
// Matthew Ward (mrward@users.sourceforge.net)
// 


using NUnit.Framework;
using SoapTrace.Core.Communication;
using System;
using System.Text;

namespace SoapTrace.Tests
{
	/// <summary>
	/// Test fixture to test a http continue response.  This test ensures
	/// that when a http continue message is received the parser will correctly
	/// extract the http message header and body.
	/// </summary>
	[ TestFixture ]
	public class HttpGetRequestTestFixture
	{
		/// <summary>
		/// The http Get header.
		/// </summary>
		private string m_HttpRequest = "GET / HTTP/1.1\r\nHost: localhost:7001\r\nUser-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20040913 Firefox/0.10.1\r\nAccept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\r\nAccept-Language: en-us,en;q=0.5\r\nAccept-Encoding: gzip,deflate\r\nAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\nKeep-Alive: 300\r\nConnection: keep-alive\r\n\r\n";
		
		/// <summary>
		/// The Soap request object under test.
		/// </summary>
		private SoapRequest m_Request = new SoapRequest( );

		/// <summary>
		/// Initialises this test fixture.
		/// </summary>
		[ SetUp ]
		public void Init( )
		{
			// Parse the message.

			byte[ ] Bytes = UnicodeEncoding.UTF8.GetBytes( m_HttpRequest );

			for( int i = 0; i < Bytes.Length; ++i )
			{
				byte MessageByte = Bytes[ i ];

				bool EndOfMessage = m_Request.AddByte( MessageByte );

				if( Bytes.Length == ( i + 1 ) )
				{
					Assert.IsTrue( EndOfMessage, "Should be at the end of the message." );
				}
				else
				{
					Assert.IsFalse( EndOfMessage, "Should not be at the end of the message." );
				}
			}
		}

		/// <summary>
		/// Test that the correct soap message has been received.
		/// </summary>
		[ Test ]
		public void MessageReceived( )
		{
			Assert.AreEqual( m_HttpRequest, m_Request.Header, "Soap Header is wrong." );
			Assert.AreEqual( "", m_Request.Message );
			Assert.AreEqual( "/", m_Request.Uri );
			Assert.AreEqual( "", m_Request.WebMethod );
			Assert.AreEqual( "", m_Request.WebService );
		}
	}
}
